package com.inspur.ourhis_afterend.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Dao.DrugsDao;
import com.inspur.ourhis_afterend.Entity.Drugs;
import com.inspur.ourhis_afterend.Service.DrugsService;
import com.inspur.ourhis_afterend.Tools.PageAction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DrugsServiceImp implements DrugsService {

    @Autowired
    DrugsDao drugsDao;

    @Override
    public IPage<Drugs> findAll(PageAction pageAction) throws Exception {
        IPage<Drugs> iPage = new Page<>(pageAction.getPageNo(), pageAction.getPageSize());
        return drugsDao.selectPage(iPage, null);
    }

    @Override
    public List<Drugs> search(String drugsid, String name) throws Exception {
        QueryWrapper<Drugs> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("drugsid", drugsid).or().like("name", name);
        return drugsDao.selectList(queryWrapper);
    }

    @Override
    public int add(Drugs drugs) throws Exception {
        return drugsDao.insert(drugs);
    }

    @Override
    public int edit(Drugs drugs) throws Exception {
        return drugsDao.updateById(drugs);
    }

    @Override
    public int del(String drugsid) throws Exception {
        return drugsDao.deleteById(drugsid);
    }
}
